package com.osgi.desktop.ui.plugins.model;

import com.onetwork.core.model.CoreTableModel;
import com.osgi.desktop.ui.util.UtilIcons;
import javax.swing.ImageIcon;
import org.osgi.framework.Bundle;

public class PluginsInstaladosTableModel extends CoreTableModel<Bundle> {
    private static final long serialVersionUID = 1L;
    public PluginsInstaladosTableModel(){
        super(new String[]{"Nome","Categoria","Em execução"});
    }

    @Override
    public Class getColumnClass(int columnIndex) {
        Class clazz = super.getColumnClass(columnIndex);
        switch(columnIndex) {
            case 2:
            clazz = ImageIcon.class;
            break;
        }
        return clazz;
    }
    
    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }

    @Override
    public void setValueAt(Object aValue, int row, int column) {
        super.setValueAt(aValue, row, column);
    }

    @Override
    public Object getValueAt(int linha, int coluna) {
        Object retorno = null;
        Bundle bundle = this.objects.get(linha);
        switch(coluna) {
            case 0:
                retorno = bundle.getSymbolicName();
                break;
            case 1:
                retorno = bundle.getBundleId();
                break;
            case 2:
                retorno = (bundle.getState() == Bundle.ACTIVE ? UtilIcons.pluginsAtivarIconPeq() : UtilIcons.pluginsDesativarIconPeq());
                break;
        }
        return retorno;
    }
}